#!/bin/bash
#set -x
set -e
usage()
{
cat << EOF
usage: $0 options

This script downloads calendar langpacks for Thunderbird.

OPTIONS:
   -h      Show this message
   -v      Version string (102.12.0)
EOF
}

VER=
while getopts “hv:” OPTION
do
     case $OPTION in
         h)
             usage
             exit 1
             ;;
         v)
             VER=$OPTARG
             ;;
         ?)
             usage
             exit
             ;;
     esac
done

if [ -z "$VER" ]
then
     echo "Missing version."
     usage
     exit 1
fi

LANG_DIR=thunderbird-langpacks
mkdir -p ${LANG_DIR}

cd ${LANG_DIR}
wget -r -c -nd -np -nH -R index.html* https://archive.mozilla.org/pub/thunderbird/releases/${VER}/linux-x86_64/xpi/
cd ..

echo "Creating ${LANG_DIR}-${VER}.tar.xz ..."
tar cJf ${LANG_DIR}-${VER}.tar.xz ${LANG_DIR}

rm -rf ${LANG_DIR}
